# _*_ coding: utf-8 _*_
# @Time : 2024-01-15 21:55
# @Author : wf
import urllib.request as request
import urllib.parse

base_url = 'https://www.baidu.com/s?'
data = {
    'wd': '周杰伦',
    "sex": '男',
    'location': '中国台湾省'
}
url = base_url + urllib.parse.urlencode(data)
print(url)

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'}
# 关键字传参
req = request.Request(url, headers=headers)
response = request.urlopen(req)
content = response.read().decode("utf8")
print(content)
